class Solution {
    public TreeNode invertTree(TreeNode root) {
        if(null != root){
            // 交换根的左右子树
            TreeNode tmp = root.left;
            root.left = root.right;
            root.right = tmp;
            // 递归反转根的左子树
            invertTree(root.left);
            // 递归反转根的右子树
            invertTree(root.right);
        }
        return root;
    }
}